/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FinancialEntity;

import VO.QuotesVO;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Sebastian
 */
@Entity
@Table(name = "quote")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Quote.findAll", query = "SELECT q FROM Quote q"),
    @NamedQuery(name = "Quote.findById", query = "SELECT q FROM Quote q WHERE q.quotePK.id = :id"),
    @NamedQuery(name = "Quote.findByLow", query = "SELECT q FROM Quote q WHERE q.low = :low"),
    @NamedQuery(name = "Quote.findByHigh", query = "SELECT q FROM Quote q WHERE q.high = :high"),
    @NamedQuery(name = "Quote.findByOpen", query = "SELECT q FROM Quote q WHERE q.open = :open"),
    @NamedQuery(name = "Quote.findByClose", query = "SELECT q FROM Quote q WHERE q.close = :close"),
    @NamedQuery(name = "Quote.findByVolume", query = "SELECT q FROM Quote q WHERE q.volume = :volume"),
    @NamedQuery(name = "Quote.findByStockid", query = "SELECT q FROM Quote q WHERE q.quotePK.stockid = :stockid")})
public class Quote implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected QuotePK quotePK;
    @Basic(optional = false)
    @Column(name = "low")
    private double low;
    @Basic(optional = false)
    @Column(name = "high")
    private double high;
    @Basic(optional = false)
    @Column(name = "open")
    private double open;
    @Basic(optional = false)
    @Column(name = "close")
    private double close;
    @Basic(optional = false)
    @Column(name = "volume")
    private double volume;
    @JoinColumn(name = "Date_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Date dateid;
    @JoinColumn(name = "Stock_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Stock stock;

    public Quote() {
    }

    public Quote(QuotePK quotePK) {
        this.quotePK = quotePK;
    }

    public Quote(QuotePK quotePK, double low, double high, double open, double close, double volume) {
        this.quotePK = quotePK;
        this.low = low;
        this.high = high;
        this.open = open;
        this.close = close;
        this.volume = volume;
    }

    public Quote(int id, int stockid) {
        this.quotePK = new QuotePK(id, stockid);
    }

    public QuotePK getQuotePK() {
        return quotePK;
    }

    public void setQuotePK(QuotePK quotePK) {
        this.quotePK = quotePK;
    }

    public double getLow() {
        return low;
    }

    public void setLow(double low) {
        this.low = low;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }

    public double getOpen() {
        return open;
    }

    public void setOpen(double open) {
        this.open = open;
    }

    public double getClose() {
        return close;
    }

    public void setClose(double close) {
        this.close = close;
    }

    public double getVolume() {
        return volume;
    }

    public void setVolume(double volume) {
        this.volume = volume;
    }

    public Date getDateid() {
        return dateid;
    }

    public void setDateid(Date dateid) {
        this.dateid = dateid;
    }

    public Stock getStock() {
        return stock;
    }

    public void setStock(Stock stock) {
        this.stock = stock;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (quotePK != null ? quotePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Quote)) {
            return false;
        }
        Quote other = (Quote) object;
        if ((this.quotePK == null && other.quotePK != null) || (this.quotePK != null && !this.quotePK.equals(other.quotePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Quote[ quotePK=" + quotePK + " ]";
    }
    
    public QuotesVO toVO(){
        QuotesVO quotevo = new QuotesVO();
        quotevo.setClose(close);
        quotevo.setDateid(dateid);
        quotevo.setHigh(high);
        quotevo.setLow(low);
        quotevo.setOpen(open);
        quotevo.setQuotePK(quotePK);
        quotevo.setStock(stock);
        quotevo.setVolume(volume);
        return quotevo;
    }
    
}
